package net.keebook.webapp.ws;

import java.util.List;

import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

import net.keebook.webapp.dao.PasswordDao;
import net.keebook.webapp.model.SessionModel;

import org.json.JSONArray;


@Path("/usersuggest")
@Stateless
public class UsernameSuggestService extends WebService {
	@Inject
	private PasswordDao passwordDao;
	
	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public String saveSettings(@Context HttpServletRequest request) {
		HttpSession session = request.getSession(true);
		SessionModel sessionModel = SessionModel.getInstance(session);
		
		Long userId = sessionModel.getUserId();
		Long keeBookId = sessionModel.getKeeBookId();
		
		List<String> items = getPasswordDao().getSuggestUsernames(userId, keeBookId);
		JSONArray result = new JSONArray(items);
		
		return result.toString();
	}

	public PasswordDao getPasswordDao() {
		return passwordDao;
	}

	public void setPasswordDao(PasswordDao passwordDao) {
		this.passwordDao = passwordDao;
	}
}
